# def test_one():
#     number=10
#     print(number)
# test_one()
# print(number)

# 10
# Traceback (most recent call last):
#   File "C:/Users/Administrator/PycharmProjects/pythonProject/第六章练习.py", line 5, in <module>
#     print(number)
# NameError: name 'number' is not defined


# def test_one():
#     number=10
#     print(number)
# def test_two():
#     number=20
#     print(number)
# test_one()
# test_two()


# number=10
# def test_one():
#     print(number)
# test_one()
# print(number)


# number=10
# def test_one():
#     print(number)
#     number+=1                                     #函数内部只能访问全局变量，不能改变全局变量。
# test_one()
# print(number)

# Traceback (most recent call last):
#   File "C:/Users/Administrator/PycharmProjects/pythonProject/第六章练习.py", line 34, in <module>
#     test_one()
#   File "C:/Users/Administrator/PycharmProjects/pythonProject/第六章练习.py", line 32, in test_one
#     print(number)
# UnboundLocalError: local variable 'number' referenced before assignment


# number=10
# def test_one():
#     global number     #global在函数中重新给number赋值。
#     number+=1
#     print(number)
# test_one()
# print(number)


# def test():
#     number=10
#     def test_in():
#         nonlocal number
#         number=20
#     test_in()
#     print(number)
# test()


# def func(num):
#     if num==1:
#         return 1
#     else:
#         return num*func(num-1)
# num=int(input("请输入一个整数："))
# result=func(num)
# print(f"{num}!=%d"%result)


# temp=lambda x:pow(x,2)
# print(temp(10))















